<%--
  Created by IntelliJ IDEA.
  User: wjc
  Date: 2021/4/7
  Time: 22:16
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <!-- 引入 Bootstrap -->
    <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
    <!-- jQuery (Bootstrap 的 JavaScript 插件需要引入 jQuery) -->
    <script src="https://code.jquery.com/jquery.js"></script>
    <title>橡树科技－JavaDemoSystem</title>
    <link type="text/css" rel="stylesheet" media="all" href="/static/styles/global.css" />
    <link type="text/css" rel="stylesheet" media="all" href="/static/styles/global_color.css" />
    <style type="text/css">
        a, a:hover, a:focus {
            text-decoration: none;
        }
    </style>
    <script language="javascript" type="text/javascript">


        //显示角色详细信息
        function showDetail(flag, a) {
            var detailDiv = a.parentNode.getElementsByTagName("div")[0];
            if (flag) {
                detailDiv.style.display = "block";
            }
            else
                detailDiv.style.display = "none";
        }
        //重置密码
        function resetPwd() {
            var flag = false;
            var inputArray = document.getElementById("datalist").getElementsByTagName("input");
            for (var i = 0; i < inputArray.length; i++) {
                if (inputArray[i].type == "checkbox") {
                    if(inputArray[i].checked){
                        flag = true;
                    }
                }
            }
            if(!flag){
                alert("请至少选择一条数据！");
                return;
            }
            var arrays = new Array();
            for (var i = 0; i < inputArray.length; i++) {
                if (inputArray[i].type == "checkbox" && inputArray[i].checked && inputArray[i].name != "all") {
                    arrays.push(inputArray[i].value);
                }
            }
            $.ajax({
                url:'${pageContext.request.contextPath}/admin/reset',
                type:'POST',
                contentType:"application/json",
                data:JSON.stringify(arrays),
                success:function(ret){
                    if(ret.code == "0"){
                        document.getElementById("operate_result_info").style.display = "block";
                    }else {
                        alert("重置密码失败")
                    }
                }
            });

        }
        //删除
        function deleteAdmin(adminId) {
            var r = window.confirm("确定要删除此管理员吗？");
            if(r){
                location.href="/admin/delete?adminId="+adminId;
            }
            // document.getElementById("operate_result_info").style.display = "block";
        }
        //全选
        function selectAdmins(inputObj) {
            var inputArray = document.getElementById("datalist").getElementsByTagName("input");
            for (var i = 1; i < inputArray.length; i++) {
                if (inputArray[i].type == "checkbox" ) {
                    inputArray[i].checked = inputObj.checked;
                }
            }
        }
    </script>
</head>
<body>
<div id="header"> <img src="/static/images/logo.png"  alt="logo" class="left"/> <a href="/logout">[退出]</a> </div>
<div id="navi">
    <ul id="menu">
        <li><a href="${pageContext.request.contextPath}/index" class="index_on"></a></li>
        <c:forEach items="${list}" var="c">
            <li><a href="${pageContext.request.contextPath}/${c.url}" class="index_on"></a></li>
        </c:forEach>
        <li><a href="user/user_info.html" class="information_off"></a></li>
        <li><a href="user/user_modi_pwd.html"  class="password_off"></a></li>
    </ul>
</div>
<div id="main">
    <form action="/admin/admin_list" method="get">
        <div class="search_add">
            <div> 模块：
                <select id="selModules" class="select_search" name="moduleId" >
                    <option value="">全部</option>
                    <c:forEach items="${moduleInfos}" var="module">
                        <option value="${module.moduleId}" ${moduleId eq module.moduleId ? "selected='selected'":""}>${module.name}</option>
                    </c:forEach>
                </select>
            </div>
            <div>角色：
                <input type="text" name="roleName" value="${roleName}" class="text_search width200"/>
            </div>

            <div>
                <input type="submit" value="搜索" class="btn_search"/>
            </div>
            <input type="button" value="密码重置" class="btn_add" onClick="resetPwd();"/>
            <input type="button" value="增加" class="btn_add" onClick="location.href='/admin/admin_add';"/>
        </div>
    </form>
        <div id="operate_result_info" class="operate_success" style="display: none"> <img src="/static/images/close.png"  onClick="this.parentNode.style.display='none';"/> <span>重置密码成功！</span> </div>
        <div id="data">
            <table id="datalist">
                <tr>
                    <th class="th_select_all"> <input type="checkbox" name="all" onClick="selectAdmins(this);"/>
                        <span>全选</span> </th>
                    <th>管理员ID</th>
                    <th>姓名</th>
                    <th>登录名</th>
                    <th>电话</th>
                    <th>电子邮件</th>
                    <th>授权日期</th>
                    <th class="width100">拥有角色</th>
                    <th class="width100">操作</th>
                    <th></th>
                </tr>
                <c:forEach items="${pageInfo.list}" var="admin">
                    <tr>
                        <td><input type="checkbox" value="${admin.adminId}"/></td>
                        <td>${admin.adminId}</td>
                        <td>${admin.name}</td>
                        <td>${admin.adminCode}</td>
                        <td>${admin.telPhone}</td>
                        <td>${admin.email}</td>
                        <td><fmt:formatDate pattern="yyyy-MM-dd" value="${admin.enrollDate}"/></td>
                        <td><a class="summary" onMouseOver="showDetail(true,this);" onMouseOut="showDetail(false,this);">
                                ${admin.roleInfos[0].name}
                                ${(fn:contains(admin.allRoleInfoNames,","))?"...":""}
                        </a>
                            <div class="detail_info"> ${admin.allRoleInfoNames}</div></td>
                        <td class="td_modi"><input type="button" value="修改" class="btn_modify" onClick="location.href='/admin/admin_modi?id=${admin.adminId}';"/>
                            <input type="button" value="删除" class="btn_delete" onClick="deleteAdmin(${admin.adminId});"/></td>
                    </tr>
                </c:forEach>


            </table>
        </div>
        <div id="pages">
            <c:if test="${pageInfo.total >= 1}">
            <c:if test="${!pageInfo.isFirstPage}">
                <a href="/admin/admin_list?pageNum=${pageInfo.pageNum - 1}&moduleId=${moduleId}&roleName=${roleName}">上一页</a>
            </c:if>
            <c:if test="${pageInfo.isFirstPage}">
                <a  href="javascript:void(0)">上一页</a>
            </c:if>
            <c:forEach begin="1" end="${pageInfo.pages}" var="i">
                <a href="/admin/admin_list?pageNum=${i}&moduleId=${moduleId}&roleName=${roleName}" class="${pageInfo.pageNum == i ? "current_page" : ""}">${i}</a>
            </c:forEach>

            <c:if test="${!pageInfo.isLastPage}">
                <a  href="/admin/admin_list?pageNum=${pageInfo.pageNum + 1}&moduleId=${moduleId}&roleName=${roleName}">下一页</a>
            </c:if>
            <c:if test="${pageInfo.isLastPage}">
                <a  href="javascript:void(0)">下一页</a>
            </c:if>
            </c:if>
        </div>

</div>
<div id="footer">
    <p>[源自橡树的技术，最优秀的师资，最真实的企业环境，最适用的实战项目]</p>
    <p>版权所有(C)橡树信息科技有限公司 </p>
</div>
</body>
</html>
